/**
 * 
 */
package visualization;

import processing.core.PApplet;

/**
 * @author alistair & david
 *
 */
public class HistoCell {

	int w;
	int h;
	int x;
	int y;
	int row;
	int col;
	boolean display_boxOffice = false;
	boolean display_count = false;
	boolean display_ratings = true;
	int	elementDisplayed = 1;
	float ratio_boxOfficeEarnings;
	float ratio_movieCount;
	float ratio_ratings;
	boolean mouseOver;
	

	
	public HistoCell(int x, int y, int w, int h, int row, int col,float ratio_movieCount, float ratio_boxOfficeEarnings, float ratio_ratings,boolean mouseOver) {

		this.w = w;
		this.h = h;
		this.x = x;
		this.y = y;
		this.row = row;
		this.col = col;
		this.ratio_boxOfficeEarnings = ratio_boxOfficeEarnings;
		this.ratio_movieCount = ratio_movieCount;
		this.ratio_ratings = ratio_ratings;
		this.mouseOver = mouseOver;
		display_boxOffice = true;
	}
	
	

	// what bar should we display
	public void displayBoxOffice (boolean value){
		display_boxOffice = value;
		if (value) elementDisplayed++; else elementDisplayed--;
	}
	
	public void displayCount (boolean value){
		display_count = value;
		if (value) elementDisplayed++; else elementDisplayed--;
	}
	
	
	public void displayRatings (boolean value){
		display_ratings = value;
		if (value) elementDisplayed++; else elementDisplayed--;
	}
	
	
	// is it displayed
	public boolean isBoxOfficeDisplayed (){
		return display_boxOffice;
	}
	
	
	public boolean isCountDisplayed (){
		return display_count;
	}
	
	public boolean isRatingsDisplayed (){
		return display_ratings;
	}
	
	

	public void draw(PApplet papp) {

		// if the ratio is negative, erroneous data, we don't display the cell
		papp.noStroke();
		
		// cell background
		if (mouseOver)				// if mouse over the cell
			if (row % 2 == 0)
				papp.fill(90,90,90);	
			else
				papp.fill(70,70,70);
				
		else
			if (row % 2 == 0)
				papp.fill(240,240,240);		// white
			else
				papp.fill(215,215,215);		// light grey
		
		papp.rect(x,y,w,h);
		papp.stroke(1);
		papp.strokeWeight(1);
		
		// box office earnings
		if (display_boxOffice)
		{
				if ((this.ratio_boxOfficeEarnings >= 0) && (h > 7) && (w > 7))
				{
					if (mouseOver)				// if mouse over the cell
						papp.fill(3,54,93);		// dark blue
					else
						papp.fill(0,128,227);	// light blue
					papp.rect(x,y,w*ratio_boxOfficeEarnings,h / elementDisplayed);
				}
				else if ((h < 7) || (w < 7))	// what if the column has been shrinked
				{
					papp.fill(0,0,0);			// black
					papp.rect(x,y,w,h);
				}
				else	// negative ratio
				{
		//			papp.rect(x,y,(float)0.1,h / elementDisplayed);
					
					if (mouseOver)
							{
								papp.fill(30);
								papp.rect(x,y,w,h / elementDisplayed);
							}
							else
							{
								papp.fill(110);
								papp.rect(x,y,w,h / elementDisplayed);
							}
						}
			
		}
		
		
		
		// movie count
		if (display_count)
		{
				if ((this.ratio_movieCount >= 0) && (h > 7) && (w > 7))
				{
					if (mouseOver)				// if mouse over the cell
						papp.fill(202,104,6);		// dark orange
					else
						papp.fill(251,187,123);	// light orange
					
					if (display_boxOffice)
						papp.rect(x,y + (h / elementDisplayed),w*ratio_movieCount,h / (elementDisplayed));
					else
						papp.rect(x,y,w*ratio_movieCount,h / (elementDisplayed) - 1);
				}
				else if ((h < 7) || (w < 7))	// what if the column has been shrinked
				{
					papp.fill(0,0,0);	
					papp.rect(x,y,w,h);
				}
				else	// negative ratio
				{
				//	papp.rect(x,y,(float)0.1,h / elementDisplayed);
					
					if (mouseOver)
						papp.fill(30);
					else
						papp.fill(110);
					
					if (display_boxOffice)
						papp.rect(x,y + (h / elementDisplayed),w,h / (elementDisplayed) + 1);
					else
						papp.rect(x,y,w,h / (elementDisplayed));
				}
	
		}
		
		
		// ratings
		if (display_ratings)
		{
				if ((this.ratio_ratings >= 0) && (h > 7) && (w > 7))
				{
					if (mouseOver)				// if mouse over the cell
						papp.fill(151,79,165);		// dark purple
					else
						papp.fill(212,170,255);	// light purple
					
					if ((display_boxOffice) && (display_count))
						papp.rect(x,y + (h / elementDisplayed) + (h / elementDisplayed) + 1,w*ratio_ratings,h / (elementDisplayed) );
					else if ((display_boxOffice) || (display_count))
						papp.rect(x,y + (h / elementDisplayed),w*ratio_ratings,h / (elementDisplayed) );
					else
						papp.rect(x,y ,w*ratio_ratings,h / (elementDisplayed));
				
				}
				else if ((h < 7) || (w < 7))	// what if the column has been shrinked
				{
					papp.fill(0,0,0);	
					papp.rect(x,y,w,h);
				}
				else	// negative ratio
				{
					//papp.rect(x,y,(float)0.1,h / elementDisplayed);
					
					if (mouseOver)
						papp.fill(30);
					else
						papp.fill(110);
					
					
					if ((display_boxOffice) && (display_count))
						papp.rect(x,y + (h / elementDisplayed) + (h / elementDisplayed) + 1,w,h / (elementDisplayed) + 1);
					else if ((display_boxOffice) || (display_count))
						papp.rect(x,y + (h / elementDisplayed),w,h / (elementDisplayed) + 1);
					else
						papp.rect(x,y ,w,h / (elementDisplayed));
			}
	
		}
			
	}
	
	
	
	
}
